package com.tengju.data.domain.model.clickhouse.star;

import com.tengju.data.domain.model.user.StarLevelEnum;
import lombok.Value;

import java.util.List;
import java.util.Optional;

@Value
public class DominationUpComing {

    Integer upComingEecNum;

    Integer upComingSecNum;

    Integer upComingEcNum;

    Integer upComingCityStarOneNum;

    Integer upComingCityStarTwoNum;

    Integer upComingCityStarThreeNum;

    Integer upComingCityStarFourNum;

    Integer upComingDealerNum;

    public static DominationUpComing zero() {
        return new DominationUpComing(0,
                0,0,0,
                0,0,
                0,0);
    }

    public Integer dealerNum() {
        return Optional.ofNullable(upComingDealerNum).orElse(0);
    }

    public Integer operatorNum() {
        return Optional.ofNullable(upComingEcNum).orElse(0)
                + Optional.ofNullable(upComingEecNum).orElse(0)
                + Optional.ofNullable(upComingSecNum).orElse(0);
    }

    public Integer serviceProviderNum() {
        return Optional.ofNullable(upComingCityStarOneNum).orElse(0)
                + Optional.ofNullable(upComingCityStarTwoNum).orElse(0)
                + Optional.ofNullable(upComingCityStarThreeNum).orElse(0)
                + Optional.ofNullable(upComingCityStarFourNum).orElse(0);
    }

    public Integer totalNum() {
        return Optional.ofNullable(upComingDealerNum).orElse(0)
                + Optional.ofNullable(upComingCityStarOneNum).orElse(0)
                + Optional.ofNullable(upComingCityStarTwoNum).orElse(0)
                + Optional.ofNullable(upComingCityStarThreeNum).orElse(0)
                + Optional.ofNullable(upComingCityStarFourNum).orElse(0)
                + Optional.ofNullable(upComingEcNum).orElse(0)
                + Optional.ofNullable(upComingEecNum).orElse(0)
                + Optional.ofNullable(upComingSecNum).orElse(0);
    }

    public Integer getTotal(List<StarLevelEnum> starLevels) {

        Integer total = 0;
        for (StarLevelEnum starLevel : starLevels) {
            Integer num = getByStarLevel(starLevel);
            total = total + num;
        }

        return total;

    }

    public Integer getByStarLevel(StarLevelEnum starLevel) {
        switch (starLevel) {
            case EEC:
                return Optional.ofNullable(upComingEecNum).orElse(0);
            case SEC:
                return Optional.ofNullable(upComingSecNum).orElse(0);
            case EC:
                return Optional.ofNullable(upComingEcNum).orElse(0);
            case CITY_STAR_ONE:
                return Optional.ofNullable(upComingCityStarOneNum).orElse(0);
            case CITY_STAR_TWO:
                return Optional.ofNullable(upComingCityStarTwoNum).orElse(0);
            case CITY_STAR_THREE:
                return Optional.ofNullable(upComingCityStarThreeNum).orElse(0);
            case CITY_STAR_FOUR:
                return Optional.ofNullable(upComingCityStarFourNum).orElse(0);
            case NONE:
                return Optional.ofNullable(upComingDealerNum).orElse(0);
            default:
                return 0;
        }
    }


}
